import vue from "@vitejs/plugin-vue";
import path from "path";
import { defineConfig } from "vite";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import { VantResolver } from "unplugin-vue-components/resolvers";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";

export default defineConfig({
  define: {
    __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: "true",
  },
  plugins: [
    vue(),
    Components({
      dirs: ["src/components"],
      resolvers: [ElementPlusResolver(), VantResolver()],
    }),
    AutoImport({
      resolvers: [ElementPlusResolver()],
      imports: [
        "vue",
        "vue-router",
        {
          "@/pinia": ["useMainStore"],
          "@/axios": ["$axios"],
          "@/assets/js/utils": ["getUserInfo", "copyObj"],
        },
      ],
    }),
    createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), "src/assets/icons/svg")], // SVG 存放路径
      symbolId: "icon-[name]",
    }),
  ],
  build: {
    minify: "terser",
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true,
      },
    },
  },
  base: "",
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
      "vue-i18n": "vue-i18n/dist/vue-i18n.cjs.js",
    },
  },
  server: {
    hmr: true,
    cors: true, // 默认启用并允许任何源
    host: "0.0.0.0",
    proxy: {
      "/mapservice/": {
        target: "https://api.map.baidu.com",
        changeOrigin: true,
        logLevel: "debug",
        rewrite: (path) => path.replace(/^\/mapservice/, "/"),
      },
      "/api/": {
        // target: 'http://192.168.1.130:33333',
        // target: 'http://localhost:36666',
        target: "http://192.168.1.253:36666",
        // target: "http://cn.qlmsmart.com",
        changeOrigin: true,
        logLevel: "debug",
        rewrite: (path) => path.replace(/^\/api/, ""),
        // rewrite: (path) => path.replace(/^\/api/, "/api/"),
      },
    },
  },
});
